package init;

import objects.CarBase;
import objects.CarNodeStore;

import java.util.List;

/**
 * @author whn
 * 初始化车辆能力矩阵和能力综合数组，用于计算连接性矩阵
 */
public class InitCarAbility {
    public static void init(CarNodeStore carNodeStore) {
        List<CarBase> list = carNodeStore.getCarList();
        int[][] relation = carNodeStore.getRelation();
        double[][] ability = carNodeStore.getAbility();
        double[] abilitySumList = carNodeStore.getAbilitySumList();
        double vi, vj, v;
        double ai, aj, a;
        double phi, phj;
        double abilityNow, abilitySum;
        for (int i = 0; i < list.size(); i++) {
            vi = list.get(i).getV();
            ai = list.get(i).getA();
            phi = list.get(i).getPh();
            abilitySum = 0;
            for (int j = i; j < list.size(); j++) {
                if (relation[i][j] == 1 && i != j) {
                    // TODO:书写添加规则，向概率矩阵添加内容
                    vj = list.get(j).getV();
                    aj = list.get(j).getA();
                    phj = list.get(j).getPh();
                    v = Math.abs(vi - vj);
                    a = Math.abs(ai - aj);
                    abilityNow = 1 / (0.3 * v + 0.4 * phj + 0.3 * a);
                    ability[i][j] = abilityNow;
                    abilitySum = abilitySum + abilityNow;
                } else {
                    ability[i][j] = 0;
                }
                abilitySumList[i] = abilitySum;
            }
        }
        carNodeStore.setAbility(ability);
        carNodeStore.setAbilitySumList(abilitySumList);
    }
}
